$(document).ready(function () {
    $("#submit").remove();
    $(".menuimg").tooltip({delay:0, showURL:false, tract:false, opacity:0.95, fixPNG:true, top:0, left:0, bodyHandler:function () {
        return $("<img/>").attr("src", this.src.replace("img_upload", "img_upload/original"))
    }});
    $(".closeCart").click(function () {
        var c = $(this).closest(".jqmWindow");
        var a = c.attr("id");
        if ($(this).hasClass("close")) {
            c.jqmHide();
            return false
        }
        var b = a.replace("cuz_", "");
        $("#food_id").val(b);
        c.jqmHide();
        $("#close_cart_confirm").jqmShow();
        return false
    });
    $(".reopenCart").click(function () {
        var a = $("#food_id").val();
        $(this).closest(".jqmWindow").jqmHide();
        $("#cuz_" + a).jqmShow();
        return false
    });
    $(".addFood").click(function () {
        var a = $(this).attr("rel");
        if ($(this).hasClass("popUp")) {
            oDisplay = $("#cuz_" + a);
            oDisplay.jqmShow();
            if (oDisplay.find(".ui-dropdownchecklist").length == 0) {
                oDisplay.find(".ddcl").dropdownchecklist({width:300, textFormatFunction:function (b) {
                    var g = b.filter(":selected");
                    var f = "";
                    for (var c = 0; c < g.size(); c++) {
                        try {
                            f += g[c].attributes.title.nodeValue + ", "
                        } catch (d) {
                        }
                    }
                    return f
                }})
            }
        } else {
            if ($(this).hasClass("Closed")) {
                autoMessage($(".error_message.message p").html())
            } else {
                add2cart("xxxxx_cuz_" + a, a)
            }
        }
        return false
    });
    $(".addToCart").click(function () {
        var a = $(this).attr("title");
        if ($(this).hasClass("Closed")) {
            $("#cuz_" + a).jqmHide();
            autoMessage($(".error_message.message p").html())
        } else {
            add2cart("xxxxx_cuz_" + a, a)
        }
        return false
    });
    $(".favorite").each(function () {
        var a = $(this).attr("rel");
        $(this).attr("href", "favorite-" + a)
    }).click(function () {
        var c = $(this).attr("rel");
        var a = "xxxxx_cuz_" + c;
        var b = "favorite_" + c;
        add2fav(a, b);
        return false
    });
    $(".addedFavorite").each(function () {
        var a = $(this).attr("rel")
    }).live("click", function () {
        autoMessage(message.added_favorite);
        return false
    });

    $('#cart-button').click(function() {
        $('html, body').animate({scrollTop:0},100);
    });
});
function fIngCheckAll(a) {
    is_checked = $("#ing_all_" + a).is(":checked");
    if (is_checked) {
        $(".ing_" + a).each(function () {
            $(this).attr("checked", "checked")
        })
    } else {
        $(".ing_" + a).each(function () {
            $(this).removeAttr("checked")
        })
    }
}
function add2cart(a, b) {
    $.ajax({url:PAGEROOT + "services/ajax.php?action=add2cart&lang=" + PAGELANG, data:$("#" + a).serialize(), type:"post", dataType:"json", beforeSend:function () {
        $("#" + a + " input[type=submit]").attr("disabled", "disabled");
        $("#" + a + " input[type=button]").attr("disabled", "disabled")
    }, complete:function () {
        $("#" + a + " input[type=submit]").removeAttr("disabled");
        $("#" + a + " input[type=button]").removeAttr("disabled");
        $("#cuz_" + b).jqmHide()
    }, success:function (c) {
        if (c.ret == true) {
            $("#frm_quan").html(c.value);
            $("#cart_number").html(c.total_number);
            if (c.error == null) {
                $("#error_cart").html("");
                $("#error_cart").attr("style", "display: none;")
            } else {
                $("#error_cart").html("<p>" + c.error + "</p>");
                $("#error_cart").attr("style", "display: block;")
            }
            if (c.warning == null) {
                $("#warning_cart").html("");
                $("#warning_cart").attr("style", "display: none;")
            } else {
                $("#warning_cart").html("<p>" + c.warning + "</p>");
                $("#warning_cart").attr("style", "display: block;")
            }
        } else {
            autoMessage(c.message)
        }
    }});
    return false
}
function add2fav(a, b) {
    $.ajax({url:PAGEROOT + "services/ajax.php?action=add2fav&lang=" + PAGELANG, data:$("#" + a).serialize(), type:"post", dataType:"json", success:function (c) {
        if (c.ret == true) {
            $("#favoriteSuccess").jqmShow();
            $("#" + b).unbind("click");
            $("#" + b).click(function () {
                return false
            });
            image_id = b.replace("favorite", "favorite_img");
            $("#" + image_id).show();
            $("#" + b).click(function () {
                autoMessage(message.added_favorite);
                return false
            })
        } else {
            autoMessage(c.message)
        }
    }})
}
;

window.onscroll=function(e){
    var getScrollTop = window.pageYOffset;
    if(getScrollTop>=48){
        $("#header").addClass('header_scroll');
        $("#search-restaurant").addClass('search-restaurant-scroll');
    }else{
        $("#search-restaurant").removeClass('search-restaurant-scroll');
        $("#header").removeClass('header_scroll');
    }
};